package com.econ.powercloud.ems.service.biz;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.econ.powercloud.common.base.facade.pojo.PageResult;
import com.econ.powercloud.ems.dal.entity.EmsArea;
import com.econ.powercloud.ems.pojo.ApiDataVO;
import com.econ.powercloud.ems.service.dao.EmsAreaDAO;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author : zjf
 * @Description : 地区 service
 * @Date : 2021/10/21 17:29
 * @Modified by : zjf
 */
@Service
public class EmsAreaService {

    @Autowired
    private EmsAreaDAO emsAreaDAO;

    public PageResult<List<ApiDataVO>> getProvinceList(String search, Integer pageNo, Integer pageSize){
        Page<EmsArea> page = emsAreaDAO.getProvinceList(search,pageNo,pageSize);
        List<ApiDataVO> apiDataVOS = Lists.newArrayList();
        for (EmsArea emsArea : page.getRecords()) {
            apiDataVOS.add(ApiDataVO.builder().code(emsArea.getCityCode()).name(emsArea.getCityName()).build());
        }
        return PageResult.<List<ApiDataVO>>builder().data(apiDataVOS)
                .pageNo((int)page.getCurrent()).totalCount((int)page.getTotal()).build();
    }

    public PageResult<List<ApiDataVO>> getCityPage(Integer province, Integer pageNo, Integer pageSize){
        Page<EmsArea> page = emsAreaDAO.getCityPage(province,pageNo,pageSize);
        List<ApiDataVO> apiDataVOS = Lists.newArrayList();
        for (EmsArea emsArea : page.getRecords()) {
            apiDataVOS.add(ApiDataVO.builder().code(emsArea.getCityCode()).name(emsArea.getCityName()).build());
        }
        return PageResult.<List<ApiDataVO>>builder().data(apiDataVOS)
                .pageNo((int)page.getCurrent()).totalCount((int)page.getTotal()).build();
    }

    public List<EmsArea> getAll() {
        return emsAreaDAO.list();
    }
}
